<template>
  <div class="login" clearfix>
    <div class="login-wrap">
      <el-row type="flex" justify="center">
<!--        :rules="rules"-->
        <el-form ref="loginForm" :model="user"  status-icon label-width="80px">
          <h3>登录</h3>
          <hr>
          <el-form-item prop="id" label="用户名">
            <el-input v-model="user.id" placeholder="请输入用户名" prefix-icon></el-input>
          </el-form-item>
          <el-form-item id="password" prop="password" label="密码">
            <el-input v-model="user.password" show-password placeholder="请输入密码"></el-input>
          </el-form-item>

          <router-link to="/register">注册账号</router-link>
          <el-form-item>
<!--      这里将el-button添加到custom HTML了，不知道会怎么样      -->
            <el-button type="primary" icon="el-icon-upload" @click="doLogin()">登 录</el-button>
          </el-form-item>
        </el-form>
      </el-row>
    </div>
  </div>
</template>

<script>
import axios from "axios";
export default {
  name: "login",
  data() {
    return {
      user: {
        id: "",
        password: ""
      }
    };
  },
  created() {
      // this.doLogin();
  },
  methods: {
    doLogin() {
      if (!this.user.id) {
        this.$message.error("请输入用户名！");
        return;
      } else if (!this.user.password) {
        this.$message.error("请输入密码！");
        return;
      } else {
        //校验用户名和密码是否正确;
        // this.$router.push({ path: "/home" });
        axios
            .post("/main/login", {
              id: this.user.id,
              password: this.user.password
            })
            .then(res => {
              // console.log("输出resp.status", res.status);
              if (res.status == 200) {
                // 登录成功进人首页
                this.$router.push({ path: "/home" });
              } else {
                alert("您输入的用户名或密码错误！");
              }
            });
      }
    }
  }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.login {
  width: 100%;
  height: 740px;
  background: url("@/assets/03.webp") no-repeat;
  background-size: cover;
  overflow: hidden;
}
.login-wrap {
  /*background: url("@/assets/01.jpg") no-repeat;*/
  background-size: cover;
  width: 400px;
  height: 300px;
  margin: 215px auto;
  overflow: hidden;
  padding-top: 10px;
  line-height: 40px;
}
#password {
  margin-bottom: 5px;
}
h3 {
  color: #0babeab8;
  font-size: 24px;
}
hr {
  background-color: #444;
  margin: 20px auto;
}
a {
  text-decoration: none;
  color: #aaa;
  font-size: 15px;
}
a:hover {
  color: coral;
}

</style>